package castledefense.data;

import castledefense.logic.Map;

public class UnitData {
	static double waterAuraRegen = 0.0000025;
	static double airAuraSpeedMultp = 1.3;
	static double fireAuraDamageMultp = 1.5;
	static double earthAuraHealthMultp = 1.5;
	
	public static double regenerationPercentFire = 0;
	public static double regenerationPercentWater = waterAuraRegen;
	public static double regenerationPercentAir = 0;
	public static double regenerationPercentEarth = 0;

	public static double speedFire = 0.03 / Map.cellWidth;
	public static double damageFire = 1;
	public static double healthFire = 50;
	public static int timeBetweenAttackFire = 2 * 1000;

	public static double speedWater = 0.03 / Map.cellWidth;
	public static double damageWater = 0.75;
	public static double healthWater = 65;
	public static int timeBetweenAttackWater = 1 * 1000 + 500;

	public static double speedEarth = 0.02 / Map.cellWidth;
	public static double damageEarth = 0.625;
	public static double healthEarth = 75;
	public static int timeBetweenAttackEarth = 2 * 1000;

	public static double speedAir = 0.04 / Map.cellWidth;
	public static double damageAir = 0.75;
	public static double healthAir = 40;
	public static int timeBetweenAttackAir = 1 * 1000;

	public static final double getRegenerationPercent(int type) {
		switch (type) {
		case (GameData.fire):
			return regenerationPercentFire;
		case (GameData.water):
			return regenerationPercentWater;
		case (GameData.earth):
			return regenerationPercentEarth;
		case (GameData.air):
			return regenerationPercentAir;
		}
		return 0;
	}

	public static final double getSpeed(int type) {
		switch (type) {
		case (GameData.fire):
			return speedFire;
		case (GameData.water):
			return speedWater;
		case (GameData.earth):
			return speedEarth;
		case (GameData.air):
			return speedAir;
		}
		return 0;
	}

	public static final double getDamage(int type) {
		switch (type) {
		case (GameData.fire):
			return damageFire;
		case (GameData.water):
			return damageWater;
		case (GameData.earth):
			return damageEarth;
		case (GameData.air):
			return damageAir;
		}
		return 0;
	}

	public static final double getHealth(int type) {
		switch (type) {
		case (GameData.fire):
			return healthFire;
		case (GameData.water):
			return healthWater;
		case (GameData.earth):
			return healthEarth;
		case (GameData.air):
			return healthAir;
		}
		return 0;
	}

	public static final int getTimeBetweenAttack(int type) {
		switch (type) {
		case (GameData.fire):
			return timeBetweenAttackFire;
		case (GameData.water):
			return timeBetweenAttackWater;
		case (GameData.earth):
			return timeBetweenAttackEarth;
		case (GameData.air):
			return timeBetweenAttackAir;
		}
		return 0;
	}

	public static final void levelUp(int type) {
		setSpeed(type, (Math.random() * 0.0025 + 1) * getSpeed(type));
		setDamage(type, (Math.random() * 0.005 + 1) * getDamage(type));
		setHealth(type, (Math.random() * 0.15 + 1.05) * getHealth(type));
		setTimeBetweenAttack(
				type,
				(int) ((1f - Math.random() * 0.1) * (float) getTimeBetweenAttack(type)));
	}

	private static final void setSpeed(int type, double newValue) {
		switch (type) {
		case (GameData.fire):
			speedFire = newValue;
		case (GameData.water):
			speedWater = newValue;
		case (GameData.earth):
			speedEarth = newValue;
		case (GameData.air):
			speedAir = newValue;
		}
	}

	private static final void setDamage(int type, double newValue) {
		switch (type) {
		case (GameData.fire):
			damageFire = newValue;
		case (GameData.water):
			damageWater = newValue;
		case (GameData.earth):
			damageEarth = newValue;
		case (GameData.air):
			damageAir = newValue;
		}
	}

	private static final void setHealth(int type, double newValue) {
		switch (type) {
		case (GameData.fire):
			healthFire = newValue;
		case (GameData.water):
			healthWater = newValue;
		case (GameData.earth):
			healthEarth = newValue;
		case (GameData.air):
			healthAir = newValue;
		}
	}

	private static final void setTimeBetweenAttack(int type, int newValue) {
		switch (type) {
		case (GameData.fire):
			timeBetweenAttackFire = newValue;
		case (GameData.water):
			timeBetweenAttackWater = newValue;
		case (GameData.earth):
			timeBetweenAttackEarth = newValue;
		case (GameData.air):
			timeBetweenAttackAir = newValue;
		}
	}

	public static final void addAura(int type) {
		isLife[type] = false;
		
		switch (type) {
		case (GameData.fire):
			addFireAura();
		case (GameData.water):
			addWaterAura();
		case (GameData.earth):
			addEarthAura();
		case (GameData.air):
			addAirAura();
		}
	}

	private static final void addWaterAura() {
		regenerationPercentFire = waterAuraRegen;
		regenerationPercentAir = waterAuraRegen;
		regenerationPercentEarth = waterAuraRegen;
	}

	private static final void addAirAura() {
		for (int i = 0; i < 4; i++) {
			setSpeed(i, getSpeed(i) * airAuraSpeedMultp);
		}
	}

	private static final void addEarthAura() {
		for (int i = 0; i < 4; i++) {
			setHealth(i, getHealth(i) * earthAuraHealthMultp);
		}
	}

	private static final void addFireAura() {
		for (int i = 0; i < 4; i++) {
			setDamage(i, getDamage(i) * fireAuraDamageMultp);
		}
	}
	public static boolean[] isLife = {true,true,true,true};
}
